/*
 create by sys on 2016/11/22.
 */

define(["require",'config/appregister',"business/Companyinfor/service/htttp","business/services/filter","jquery","business/workSkill/directive/startLevel"],function(require,app,httpServices){
    app.controller('friendCtrl',function($scope,$timeout,$state,auth){
        auth.isCompanyLogin();
	$scope.listParams = {
            currentTcId: "",
            download: false,
            time: false,
            pageNo: 1,
            pageSize:6,
            all: false,
            typeId: "",
            scId: "",
            dcId: "",
            keyWord:"",
            //dcName scName 用于加入缓存 在详情中显示面包树导航
            dcName:"",
            scName:""
        };
        $scope.noContent2="还没关注人呢，赶紧去关注吧！"
	function getSee(){
		var req ={
                type:"GET",
                uri:"getFollowList",
                data:{
                   pageNo:$scope.listParams.pageNo,
                   pageSize:$scope.listParams.pageSize
                }
            };
            httpServices.getCOmpanyFollow(req).success(function(result){
                $scope.$apply(function(){
                    $scope.frendCon = result.data.list;
                	$scope.totalItem = result.data.Pagination.totalCount;
                   	getListModel();
                })
            });
		}
      getSee();
        $scope.FriendTab=1;
		$scope.follow=function(){
			$scope.FriendTab=1;
			getSee();
		}
		
		
		$scope.listParams2 = {
            currentTcId: "",
            download: false,
            time: false,
            pageNo: 1,
            pageSize:6,
            all: false,
            typeId: "",
            scId: "",
            dcId: "",
            keyWord:"",
            //dcName scName 用于加入缓存 在详情中显示面包树导航
            dcName:"",
            scName:""
        };
		
		
		$scope.Fans=function(){
			$scope.FriendTab=2;
			getFans();
		}
		function getFans(){
			var req ={
                type:"GET",
                uri:"getByFollowList",
                data:{
                   pageNo:$scope.listParams2.pageNo,
                   pageSize:$scope.listParams2.pageSize
                }
            };
            httpServices.getCOmpanyFollow(req).success(function(result){
                $scope.$apply(function(){
                    $scope.frendCon = result.data.list;
                    $scope.totalItem = result.data.Pagination.totalCount;
                    getListModel2();
                })
            });
		}
		
			 $scope.list = [];
        function getListModel2(){
            $scope.paginationConf = {
                currentPage: $scope.listParams2.pageNo,
                totalItems: $scope.totalItem,
                //每页预览条数
                itemsPerPage:$scope.listParams2.pageSize,
                //分页总数
                numberOfPages:Math.ceil($scope.totalItem/$scope.listParams2.pageSize),
                // 实际分页长度
                pagesLength:5,
                perPageOptions: [10, 20, 30, 40, 50],
                onChange: function (currentPage) {
                    if(currentPage){
                        $scope.paginationConf.currentPage = currentPage;
                    }
                    $scope.list = [];
                    $scope.listParams2.pageNo = $scope.paginationConf.currentPage;
                    getSee();

                }
            };
        }

		
		
		
		$scope.markC=true;
		$scope.markD=true;
		$scope.cacelSeeTwo=function(item,$index){
            if($scope.FriendTab==1){
                var id = item.followUserId;
            }else{
                var id = item.userId;
            }
			item.isFollow=1;
    		$($(".FriendPro")[$index]).animate({"opacity":"1"});
            $($(".FriendPro")[$index]).animate({"opacity":"0"});
          	$($(".FriendPro")[$index]).text("关注成功")
              	var req ={
                type:"POST",
                uri:"follow",
                data:{
                  followUserId:id
                }
            };
            httpServices.getCOmpanyFollow(req).success(function(result){
                $scope.$apply(function(){
                    
                })
            });
         
		}
        $scope.cacelSeeOne=function(item,$index){
		    if($scope.FriendTab==1){
                var id = item.followUserId;
            }else{
                var id = item.userId;
            }

        	item.isFollow=0;
    		$($(".FriendPro")[$index]).animate({"opacity":"1"});
            $($(".FriendPro")[$index]).animate({"opacity":"0"});
          	$($(".FriendPro")[$index]).text("取消成功")
             var req ={
                type:"POST",
                uri:"follow",
                data:{
                 	 followUserId:id
                }
	            };
	            httpServices.getCOmpanyFollow(req).success(function(result){
	               	 $scope.$apply(function(){
	                    
	               	 })
            	});	
        }
        $scope.ReindDele2=function(item,$index){
        	var id = item.followUserId;
        	item.isStaff=0
        	    var req ={
                type:"POST",
                uri:"staff",
                data:{
                  staffUserId:id
                }
            };
            httpServices.getCOmpanystaff(req).success(function(result){
                $scope.$apply(function(){
                    
                })
            });
        }
        $scope.ReindDele=function(item,$index){
        	item.isStaff=1
            var id = item.followUserId;
	          var req ={
	            type:"POST",
	            uri:"staff",
	            data:{
	              staffUserId:id
	            }
	            };
	            httpServices.getCOmpanystaff(req).success(function(result){
	                $scope.$apply(function(){
	                    
	                })
	            });
          
        }
		 $scope.list = [];
        function getListModel(){
            $scope.paginationConf = {
                currentPage: $scope.listParams.pageNo,
                totalItems: $scope.totalItem,
                //每页预览条数
                itemsPerPage:$scope.listParams.pageSize,
                //分页总数
                numberOfPages:Math.ceil($scope.totalItem/$scope.listParams.pageSize),
                // 实际分页长度
                pagesLength:5,
                perPageOptions: [10, 20, 30, 40, 50],
                onChange: function (currentPage) {
                    if(currentPage){
                        $scope.paginationConf.currentPage = currentPage;
                    }
                    $scope.list = [];
                    $scope.listParams.pageNo = $scope.paginationConf.currentPage;
                    getSee();

                }
            };
        }

        $scope.senMessage=function(index){
            $scope.username=$($(".FriendName")[index]).text();
            $scope.byuseId=$($(".freindList")[index]).attr("id");
            $scope.message=1;
            $($(".freindList")[index]).offset();
            $(".bomb-box").css({'left':$(".freindList").eq(index).offset().left,'top':$(".freindList").eq(index).offset().top+80})
        }
        $scope.saveMesageCon=function(con){
            $scope.messCon = con;
        }
        $scope.offbomb=function(){
            $scope.message=2;
        }
        $scope.domsg=function(){
            if($scope.messCon == undefined){
                alert("不可发送空信息")
            }else{
                $scope.message=2;
                var req ={
                    type:"POST",
                    uri:"addMessage",
                    data:{
                        byUserId:$scope.byuseId,
                        content:$scope.messCon
                    }
                };
                httpServices.postMesasage(req).success(function(result){
                    $scope.$apply(function(){
                       
                        
                    })
                });
            }

        }
    
    	$scope.headerLink=function(item){
			 $state.go("othersMainPage",{userId:item.userId})
		}
    
    })
});
